package test.demo;



import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import tech.waterism.modelbase.PredictBase;
import tech.waterism.modelbase.PredictResult;

import java.util.*;

/**
 * 大伙房模型（大伙房产汇流）更新状态版
 */
public class DHF_BLH extends PredictBase {


    final static double PAI = (Math.PI); //圆周率
    // 产流
    private double SMAX; //表示现在时刻的上层蓄水容量
    private double UMAX; //表示现在时刻的下层蓄水容量
    private double d0; //地下水蓄水容量，即下层蓄水容量与地下水库蓄水容量之和
    private double s00; //初始表层蓄水容量(6月1号8时)
    private double u00; //初始下层蓄水容量(6月1号8时)
    private double sd; //表层蓄水容量增量
    private double ud; //下层蓄水容量增量
    private double k2; //点的下层下渗曲线的曲率系数
    private double ka; //前期净雨折减系数,ka = 0.15
    private double g; //不透水面积比例
    private double a; //表层蓄水容量空间分布曲线形状参数
    private double B; //流域内下渗率抛物线形状系数（总下渗或下层下渗）
    private double s0;
    private double u0;
    private double Pc, y0, PE, E, Sm, rr, un, dn, Ec, EL, Z1, Z2, Eu;
    private double y = 0.0f;
    //汇流
    private double AA; //不同的曲线参数
    private double DD; //不同的曲线参数
    private double CC; //不同的曲线参数
    private double KB; //不同的曲线参数k3,汇流曲线比例系数
    private double COE; //不同的曲线参数
    private double B0; //特征河长比例系数，为待定参数
    private double K0; //汇流曲线底宽指数，为待定参数
    private double K; //前期净雨影响衰减系数，是否为k？
    private double N; //地下径流与地面壤中流汇流曲线底宽的比例系数
    private double L; //流域最大河长
    private double AAL, DDL, CCL, KBL, Tm, LB; //地下径流参数
    // 产汇流中间变量
    private double[] r;
    private double[] rL;
    // other
    /**
     * 初始流域表层平均蓄水量
     */
    private double sa0;

    /**
     * 初始流域下层平均蓄水量
     */
    private double ua0;

    /**
     * 初始前期影响雨量
     */
    private double ya0;
    //
    private Date dt_beg;
    /**
     * 降水时间
     */
    private Date[] floodTm;

    /**
     * 降水量
     */
    private double[] floodDrp;

    /**
     * 降水序列长度
     */
    private Integer floodRainRange;

    /**
     * 降水时段长
     */
    private double timeInterval;
    /**
     * 流域 月蒸发量（mm）
     */
    private double[] ES;

    /**
     * 流域 时段蒸发量（mm）
     */
    private double[] floodE;
    /**
     * 流域蒸散发折算系数
     */
    private double Kc;
    /**
     * 模拟总径流
     */
    private double[] QSim;

    //ghj0710================================================================
    private double[] sa;
    private double[] ua;
    private double[] ya;
//0710========================================================================
    public DHF_BLH(Map<String, String> data) {
        super();
        setDataFromRequest(data);
        floodRainRange = floodDrp.length;
        QSim = new double[floodRainRange];
        System.out.println("初始 SA0 = " + sa0 + ", UA0 = " + ua0 + ", YA0 = " + ya0);
    }

   /*public static void main(String[] args) {
        String a = "{\"DD\":\"1.2\",\"A\":\"2.4\",\"B\":\"2\",\"K0\":\"0.5\",\"G\":\"0.05\",\"K2\":\"0.6\"," +
                "\"K3\":\"4638\",\"K\":\"0.9\",\"L\":\"130\",\"DDL\":\"1.2\",\"N\":\"3.2\",\"UD\":\"1\"," +
                "\"dt\":\"[\\\"2025-02-18 13:54:10\\\",\\\"2025-02-18 14:54:10\\\",\\\"2025-02-18 15:54:10\\\"]\",\"SD\":\"1\",\"S00\":\"15\",\"KBL\":\"4638\"," +
                "\"U00\":\"40\",\"KA\":\"0.9\",\"COE\":\"0.3\",\"AA\":\"2\",\"CC\":\"1.2\",\"rain\":\"[0.0,0.0,8.0]\",\"SA0\":\"5.000\",\"UA0\":\"0.000\",\"start\":\"\\\"2025-02-18 13:54:10\\\"\"," +
                "\"YA0\":\"0.500\",\"AAL\":\"2\",\"D0\":\"110\",\"CCL\":\"1.2\",\"B0\":\"1.2\",\"ES\":\"[23" +
                ".8, 23.2, 33.7, 53, 66.6, 78.9, 122.3, 113.9, 90.8, 62.9, 46.2, 34.1]\",\"q\":\"[0.0,0.0]\"," +
                "\"runoffSim\":\"[]\",\"U0\":\"90\",\"clen\":\"1\",\"S0\":\"50\"}";
        Map data = JSON.parseObject(a, Map.class);
        DHF_BLH obj = new DHF_BLH(data);
        System.out.println(obj.predict());
    }*/

   public static void main(String[] args) {
       String resultFileName = "C:\\Users\\25468\\Desktop\\daima0620\\model-java-demo-master2\\src\\main\\java\\test\\demo\\20810200-方案186-DHF_BLH-1752197548037.txt";
       String a = FileUtil.readString(resultFileName, "utf-8");
       Map data = JSON.parseObject(a, Map.class);
       DHF_BLH obj = new DHF_BLH(data);
       System.out.println(obj.predict());
   }



    private void setDataFromRequest(Map<String, String> data) {
        sa0 = Double.parseDouble(data.get("SA0"));
        ua0 = Double.parseDouble(data.get("UA0"));
        ya0 = Double.parseDouble(data.get("YA0"));
        // 产流参数
        SMAX = Double.parseDouble(data.get("S0"));
        UMAX = Double.parseDouble(data.get("U0"));
        d0 = Double.parseDouble(data.get("D0"));
        s00 = Double.parseDouble(data.get("S00"));
        u00 = Double.parseDouble(data.get("U00"));
        sd = Double.parseDouble(data.get("SD"));
        ud = Double.parseDouble(data.get("UD"));
        k2 = Double.parseDouble(data.get("K2"));
        ka = Double.parseDouble(data.get("KA"));
        g = Double.parseDouble(data.get("G"));
        a = Double.parseDouble(data.get("A"));
        B = Double.parseDouble(data.get("B"));
        s0 = Double.parseDouble(data.get("S0"));
        u0 = Double.parseDouble(data.get("U0"));
        Kc = Double.parseDouble(data.get("K"));
        // 汇流参数
        AA = Double.parseDouble(data.get("AA"));
        DD = Double.parseDouble(data.get("DD"));
        CC = Double.parseDouble(data.get("CC"));
        KB = Double.parseDouble(data.get("K3"));
        COE = Double.parseDouble(data.get("COE"));
        B0 = Double.parseDouble(data.get("B0"));
        K0 = Double.parseDouble(data.get("K0"));
        K = Double.parseDouble(data.get("K"));
        N = Double.parseDouble(data.get("N"));
        L = Double.parseDouble(data.get("L"));
        AAL = Double.parseDouble(data.get("AAL"));
        DDL = Double.parseDouble(data.get("DDL"));
        CCL = Double.parseDouble(data.get("CCL"));
        KBL = Double.parseDouble(data.get("KBL"));
        //
        ES = JSON.parseObject(data.get("ES"), double[].class);
        floodTm = JSON.parseObject(data.get("dt"), Date[].class);// input[i].data.dt
        floodDrp = JSON.parseObject(data.get("rain"), double[].class);// input[i].data.rain
        floodE = JSON.parseObject(data.get("evaporation"), double[].class);  // input[i].data.evaporation
        timeInterval = Double.parseDouble(data.get("clen"));                  // index.clen
        dt_beg = JSON.parseObject(data.get("start"), Date.class);


    }

    private Date getEightTime(Date dt) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.set(Calendar.HOUR_OF_DAY, 8);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    private Date getDT(Date dt, int month, int day, int hour) {// 设置6月1号8时的时间
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DAY_OF_MONTH, day);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    private int daysAfter(Date dt_beg, Date dt_end) {// 两个时间相差的天数
        int days = -1;
        if ((dt_end.getTime() - dt_beg.getTime()) >= 0) {
            days = Long.valueOf((dt_end.getTime() - dt_beg.getTime()) / (24 * 3600 * 1000l)).intValue();
        }
        return days;
    }

    /**
     * 蒸发计算
     *
     * @param date   降水时间
     * @param timeIn 时间间隔 (h)
     * @return 蒸发
     */
    private double calcEvaporationPotential(Date date, double timeIn) {
        Calendar time = Calendar.getInstance();
        time.setTime(date);
        Integer Month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份
        double Ep = ES[Month - 1] / 30; // 月蒸发量转换成日蒸发量
        Ep = Ep * timeIn / 24; // 日蒸发量转换成时段蒸发量
        return Ep;
    }

    //大伙房模型的产流计算
    private void dhf_runoff() {
        //dt_beg—降雨开始时间，timeInterval—表示时间间隔，i_periods—表示降雨时段数，floodDrp—降雨值，
        //emt—表示各月蒸发能力，sa0—初始表层流域平均蓄水量，ua0—初始下层土壤蓄水量，ya0—初始前期影响雨量
        //sa—表层蓄水量，ua—下层蓄水量，r—总径流，rL—地下径流，ya—前期影响雨量

        //ghj0710===========================================================
        sa = new double[floodRainRange + 1];
        ua = new double[floodRainRange + 1];
        ya = new double[floodRainRange + 1];
        //0710添加=======================================================================

        if (sa0 > s0)
            sa0 = s0;
        if (ua0 > u0)
            ua0 = u0;
//ghj0711=================================================================================================
       /*  double[] sa = new double[floodRainRange + 1]; // 循环计算时多一个时段  上层土壤含水量
        double[] ua = new double[floodRainRange + 1]; // 下层土壤含水量
        double[] ya = new double[floodRainRange + 1]; // 前期影响雨量*/
        //======================================================================
        r = new double[floodRainRange];
        rL = new double[floodRainRange];

        sa[0] = sa0; //初始表层蓄水量
        ua[0] = ua0; //初始下层蓄水量
        ya[0] = ya0; //初始前期影响雨量

        Date dt_618 = getDT(dt_beg, 5, 1, 8); //设置6月1日早8时的时间
        for (int i = 0; i < floodRainRange; i++) {
            double yu, yL = 0.0f; //地面壤中流和地下径流
            double Eb = 0.0f; //初始化Eb
            Date temp_time = floodTm[i];
            Date dt_rain = getEightTime(temp_time); //降雨开始时间
            int interval = daysAfter(dt_618, dt_rain); //两个时间相差的天数
            if (interval <= 0) {
                s0 = s00;
                u0 = u00;
            } else {
                s0 = s00 + interval * sd; //表示降雨开始时刻上层蓄水量容量
                u0 = u00 + interval * ud; //表示降雨开始时刻下层蓄水量容量
            }
            if (s0 > SMAX)
                s0 = SMAX;
            if (u0 > UMAX)
                u0 = UMAX;

            //以下计算蒸发量
            // E = f_emt(emt, floodDrp[i], dt_rain, timeInterval); //E--雨间蒸散发量
            if (floodE == null || floodE.length != floodRainRange) {
                E = Kc * calcEvaporationPotential(floodTm[i], timeInterval);
            } else {
                E = Kc * floodE[i];
            }

            PE = floodDrp[i] - E; //PE--净雨强,floodDrp[i]-第i时段的降雨量

            y0 = g * PE; //y0--不透水面积上的直接径流
            Pc = PE - y0; //Pc--净渗雨强
            // System.out.println("********Pc:"+Pc+",PE:"+PE+",E="+E+",P["+i+"]="+floodDrp[i]+"g="+g+"y0="+y0);

            //地面壤中流和地下径流之和y的计算:
            //-----------当降雨量超过流域蒸发能力时，即净渗雨强Pc>0------------//
            if (Pc > 0.0f) {
                double temp = (Math.pow(1 - sa[i] / s0, 1 / a));
                Sm = a * s0 * (1 - temp); // 2-103,Sm--相应于Sa的点蓄水量
                if (Sm + Pc < a * s0) {
                    temp = (Math.pow(1 - (Sm + Pc) / (a * s0), a));
                    rr = Pc + sa[i] - s0 + s0 * temp; //2-104,R--下渗强度
                } else
                    rr = Pc - (s0 - sa[i]); //2-96
                //System.out.println("^^^^^^^^^^rr="+rr+",s0="+s0);
                /*********************表层***********************/
                temp = (Math.pow(1 - ua[i] / u0, 1 / B));
                un = B * u0 * (1 - temp); //2-128
                temp = (Math.pow(1 - ua[i] / u0, u0 / (B * d0)));
                dn = B * d0 * (1 - temp); //2-133

                Z1 = (1 - Math.exp(-k2 * timeInterval * u0 / d0)); //2-119
                Z2 = (1 - Math.exp(-k2 * timeInterval)); //2-120
                //地面壤中流和地下径流之和
                if (rr + Z2 * un < Z2 * B * u0) {
                    temp = (Math.pow((1 - (Z2 * un + rr) / (Z2 * B * u0)), B));
                    y = rr + Z2 * (ua[i] - u0) + Z2 * u0 * temp; //2-129
                } else
                    y = rr + Z2 * (ua[i] - u0); //2-130
                //求地面壤中流yu
                temp = (Math.pow(1 - ua[i] / u0, u0 / d0));
                if (Z1 * dn + rr < Z1 * B * d0) {
                    double temp1 = 1 - (Z1 * dn + rr) / (Z1 * B * d0);
                    double temp2 = (Math.pow(temp1, B));
                    yu = rr - Z1 * d0 * temp + Z1 * d0 * temp2; //2-131
                } else
                    yu = rr - Z1 * d0 * temp; //2-132
                //求地下径流yL
                yL = y - yu; //2-134
                //表面蓄水量计算sa[i+1]
                if (Sm + Pc < a * s0) {
                    double temp1 = 1 - (Sm + Pc) / (a * s0);
                    double temp2 = (Math.pow(temp1, a));
                    sa[i + 1] = s0 * (1 - temp2); //2-138
                    //System.out.println("@@@@@@@@@E: "+E+",sa["+(i+1)+"]="+sa[i+1]);
                } else {
                    sa[i + 1] = sa[i] + Pc - rr; //2-140
                    //System.out.println("######E: "+E+",sa["+(i+1)+"]="+sa[i+1]);
                }
                if (sa[i + 1] > s0)
                    sa[i + 1] = s0; //表层蓄水量不能超过超过表层蓄水容量，即饱和状态
                //下层土壤蓄水量ua[i+1]
                ua[i + 1] = ua[i] + rr - y; //2-141
                if (ua[i + 1] > u0)
                    ua[i + 1] = u0;
                Eb = 0.0f;
            }
            //---------当日流域平均降雨量小于流域平均蒸散发能力，即P<Ed时--------//
            else if (floodDrp[i] < E) {
                Ec = E - floodDrp[i]; //2-144
                Eb = Eb + Ec; //2-145
                if (Eb > s0)
                    Eb = s0; //限制蒸发深度

                //表层可蒸发量Eu,两个假定
                double temp1 = (Math.pow(1 - (Eb - Ec) / (a * s0), a));
                double temp2 = (Math.pow(1 - Eb / (a * s0), a));
                //Eu = s0 * (temp1 - temp2); //2-146
                ////////防止出现负数///////////////
                if (Eb / (a * s0) <= 0.999999 & (Eb - Ec) / (a * s0) <= 0.999999) {
                    Eu = s0 * (temp1 - temp2); // 2-146
                } else if (Eb / (a * s0) >= 1.00001 & (Eb - Ec) / (a * s0) <= 0.999999) {
                    Eu = s0 * Double.valueOf(Math.pow(temp1, a)).floatValue();
                } else {
                    Eu = 0.00001f;
                }

                sa[i + 1] = sa[i] - Eu; //2-147

                //下层蓄水量计算ua[i+1],两个假定
                if (sa[i] - Eu < 0.0f) {
                    sa[i + 1] = 0.0f;
                    EL = (Ec - sa[i]) * ua[i] / u0; //2-149
                } else
                    EL = (Ec - Eu) * ua[i] / u0; //2-148
                ua[i + 1] = ua[i] - EL; //2-150
                if (ua[i + 1] < 0.0f)
                    ua[i + 1] = 0.0f;

                rr = 0.0f; //下渗强度
                y = 0.0f; //表层径流和地下径流之和
                y0 = 0.0f; //直接径流
                yL = 0.0f; //地下径流
            }
            r[i] = y + y0; //总径流,2-137
            if (r[i] <= 0)
                r[i] = 0;
            rL[i] = yL; //地下水库下渗强度
            ya[i + 1] = (ya[i] + r[i]) * ka;
            if (ya[i + 1] <= 0)
                ya[i + 1] = 0;
        }
       //===========================ghj0716加
        double totalR = 0;
        for (double ri : r) totalR += ri;
        System.out.println("Total runoff (r[i]): " + totalR);
    }

    public int flow_dhf() {// 汇流
        int i_floods = 0;
        double YA = ya0;
        int TT, TS, TL = 0;
//=====================================================0717ghj
        // ===== 新增 START =====
        // 计算总径流量用于归一化
        double totalRunoff = 0;
        for (int i = 0; i < floodRainRange; i++) {
            totalRunoff += (r[i] - rL[i]); // 地表径流部分
        }
        double totalRunoffL = 0;
        for (int i = 0; i < floodRainRange; i++) {
            totalRunoffL += rL[i]; // 地下径流部分
        }
        // ===== 新增 END =====

        for (int i = 0; i < floodRainRange; i++) {// i—时段
            double temp = Double.valueOf(Math.pow(YA + r[i], -K0));
            Tm = (L / B0) * temp;// 表层和壤中流的底宽
            YA = (YA + r[i]) * K;
            TT = (int)(Tm * N);// 地下径流汇流曲线底宽
            TS = (int)(Tm * COE);// 地下径流出现相对于表层和壤中流出现推迟的时间
            TL = TT + TS - 1;// 整个底宽
            if (TL < 0) {
                TL = 0;
            } // 防止TL<0
            // System.out.println("TL="+TL);
//============================================================================0717ghj
            // ===== 新增 START =====
            // 计算当前时段的权重总和用于归一化
            double surfaceWeightSum = 0;
            double undergroundWeightSum = 0;

            // 先计算权重总和
            for (int j = 0; j < TL; j++) {
                if (i + j == QSim.length) {
                    break;
                }

                double tmp1 = PAI * j / Tm;
                double surfaceWeight = Math.exp(-AA * Math.pow(tmp1, CC)) * Math.pow(Math.sin(tmp1), DD);

                double tmp2 = PAI * (j - TS) / TT;
                double undergroundWeight = Math.exp(-AAL * Math.pow(tmp2, CCL)) * Math.pow(Math.sin(tmp2), DDL);

                if (j <= Tm) {
                    surfaceWeightSum += surfaceWeight;
                    if (j > TS) {
                        undergroundWeightSum += undergroundWeight;
                    }
                } else {
                    undergroundWeightSum += undergroundWeight;
                }
            }
            // ===== 新增 END =====

            for (int j = 0; j < TL; j++) {// 每时刻曲线形状不同
                if (i + j == QSim.length) {// 怕越界/////////////////彭勇//////////////////
                    TL = j;
                    break;
                }

               /* double tmp1 = PAI * j / Tm;// 表层和壤中流,n=1,KB就是K3//0717注释
                double temp1 = (r[i] - rL[i]) * KB / Tm *
                        (Double.valueOf(Math.exp(-AA * Math.pow(tmp1, CC)) * Math.pow(Math.sin(tmp1), DD)).floatValue());
                double tmp2 = PAI * (j - TS) / TT;// 地下径流,n=n,Tm*n,KBL就是K3
                double temp2 = rL[i] * KBL / TT *
                        (Double.valueOf(Math.exp(-AAL * Math.pow(tmp2, CCL)) * Math.pow(Math.sin(tmp2), DDL)).floatValue());*/

                // ===== 修改 START =====0717ghj
                double tmp1 = PAI * j / Tm;// 表层和壤中流,n=1,KB就是K3
                double surfaceWeight = Math.exp(-AA * Math.pow(tmp1, CC)) * Math.pow(Math.sin(tmp1), DD);
                double temp1 = 0;
                if (surfaceWeightSum > 0) {
                    temp1 = (r[i] - rL[i]) * KB / Tm * (surfaceWeight / surfaceWeightSum);
                }

                double tmp2 = PAI * (j - TS) / TT;// 地下径流,n=n,Tm*n,KBL就是K3
                double undergroundWeight = Math.exp(-AAL * Math.pow(tmp2, CCL)) * Math.pow(Math.sin(tmp2), DDL);
                double temp2 = 0;
                if (undergroundWeightSum > 0) {
                    temp2 = rL[i] * KBL / TT * (undergroundWeight / undergroundWeightSum);
                }
                // ===== 修改 END =====

                if (j <= Tm) {
                    if (j <= TS) {
                        QSim[i + j] += temp1;
                    } else {
                        QSim[i + j] += temp1 + temp2;
                    }
                } else {
                    QSim[i + j] += temp2;
                }
                if (QSim[i + j] < 0)
                    QSim[i + j] = 0;
            }
        }
        i_floods = TL + floodRainRange;
        if (TL == 0) {
            i_floods = i_floods + 1;
        }
       //========================================0717ghj
        double totalQSim = 0;
        for (double q : QSim) totalQSim += q;
        System.out.println("Total QSim: " + totalQSim);
        //=========================================0717
        return i_floods;

    }

    public Map<String, double[]> DHF_Model() {
        //大伙房产流
        dhf_runoff();

        // for (Integer j = 0; j < floodRainRange; j++) {
        //     RunoffSim[j] = y[j] + y0[j]; //总径流,2-137
        //     if (RunoffSim[j] < 0.0) {
        //         RunoffSim[j] = 0.0;
        //     }
        //     rL[j] = yL[j]; //地下水库下渗强度
        //     if (rL[j] < 0.0) {
        //         rL[j] = 0.0;
        //     }
        //
        //     /*需保留最后一个时段末的状态值，去掉时段初值限制条件*/
        //     //            if(j + 1 < floodRainRange) {
        //     ya[j + 1] = (ya[j] + RunoffSim[j]) * Ka;// 2-153
        //     if (ya[j + 1] < 0.0) {
        //         ya[j + 1] = 0.0;
        //     }
        //
        //     //            }
        // }

        //大伙房汇流
        flow_dhf();

        Map<String, double[]> simulationResult = new HashMap<>();

        // simulationResult.put("rain", floodDrp);
        // simulationResult.put("PE", PE);
        simulationResult.put("runoffSim", r);
        // simulationResult.put("y0", y0);
        // simulationResult.put("yu", yu);
        // simulationResult.put("yL", yL);
        // simulationResult.put("y", y);
        // simulationResult.put("qs", qs);
        // simulationResult.put("ql", ql);
        simulationResult.put("QSim", QSim);

        return simulationResult;
    }

    @Override
    public void init() {

    }

    @Override
    public PredictResult predict() {
        PredictResult result = new PredictResult();
        Map<String, double[]> map = DHF_Model();


        double[][] RSim = new double[4][];
        // //不透水面积产流
        // RSim[0] = map.get("y0");
        // //流域地表壤中流
        // RSim[1] = map.get("yu");
        // //流域地下径流
        // RSim[2] = map.get("yL");
        // //流域地表壤中流与地下径流之和
        // RSim[3] = map.get("y");

        //流域面积总产流，不透水面积产流y0[j]+ 流域表层径流yu[j] +  流域地下径流yL[j];
        result.setRunoffSim(map.get("runoffSim"));
        // result.setRSim(RSim);
        //汇流计算结果
        result.setQSim(map.get("QSim"));
        //ghj0710==========================================================
       /* List<String> sap = toStringList(sa);
        List<String> uap = toStringList(ua);
        List<String> yap = toStringList(ya);*/

     //ghj 0711==============================================================================
        List<String> sap = toStringList(Arrays.copyOfRange(sa, 0, sa.length));
        List<String> uap = toStringList(Arrays.copyOfRange(ua, 0, ua.length));
        List<String> yap = toStringList(Arrays.copyOfRange(ya, 0, ya.length));




        //  todo 更新状态
        Map<String, List<String>> status = new HashMap<>();
        //ghj修改开始0710=====================================================
       /* status.put("SA0", sap);
        //下层蓄水量
        status.put("UA0", uap);
        //前期影响雨量
        status.put("YA0", yap);*/
//GHJ修改结束0710======================================================================


        //ghj0711=======================================
        status.put("SA0", sap);
        status.put("UA0", uap);
        status.put("YA0", yap);

        result.setNewStatus(status);
        return result;
    }
    //ghj0710==========================================================
    private List<String> toStringList(double[] array0) {
        String[] array = new String[array0.length];
        for (int i = 0; i < array.length; i++) {
            array[i] = String.valueOf(array0[i]);
        }
        return Arrays.asList(array);
    }
}
